/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package upeu.edu.pe.controlador;

/**
 *
 * @author Administrador
 */
/*
import java.util.HashMap;
import java.util.Map;
import upeu.edu.pe.modelo.SauUsuario;
import upeu.edu.pe.servicio.SauUsuarioServicio;
import upeu.edu.pe.utils.STRCrypto;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller(value="SauUsuarioController")
public class SauUsuarioController {

        //protected final Log logger = LogFactory.getLog(SivEmpresaController.class);
	
        @Autowired(required=true)
	public SauUsuarioServicio UsuarioServicio;
       
            
        @RequestMapping(value = "validar/login", method = RequestMethod.POST)
        public ModelAndView loginRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map model = new HashMap();
        String result="";
        SauUsuario usuario=new SauUsuario();
        STRCrypto crypt=new STRCrypto();
        usuario.setUsuario(request.getParameter("username"));
        usuario.setClave(crypt.encrypt(request.getParameter("clave")));       
        List list= UsuarioServicio.validarUsuario(usuario);
               Iterator iterator = list.iterator();
               if(iterator.hasNext()){
               SauUsuario to=(SauUsuario)iterator.next();                              
               if(to.getEstado().equals("1")){
                int l = Integer.parseInt(String.valueOf(to.getIdCategoriaUsuario()));               
                request.getSession().setAttribute("Username", request.getParameter("username"));
                request.getSession().setAttribute("UserId", to.getIdUsuario());
                //request.getSession().setAttribute("NivelFsx", to.getNivel());
                    if(l<=5) {
                            request.getSession().setAttribute("Session2", request.getSession().getId()); 
                            ArrayList list_s= new ArrayList();
                            for (int i = l; i<=3; i++){
                                    list_s.add(""+i);
                            }						
                            //1 Super Administrador
                            //2 Administrador
                            //3 Promotor Ventas
                            //4 Apoyo Ventas
                            //5 Auditor						
                      request.getSession().setAttribute("ListAccesses",list_s);
                      }
                    result="5|Exito|validar/frame.html";                
                }else{
                if(!to.getEstado().equals("1") && to.getIdCategoriaUsuario().equals("1")){
                        int l = Integer.parseInt(String.valueOf(to.getIdCategoriaUsuario()));
                        request.getSession().setAttribute("Username", request.getParameter("username"));
                        request.getSession().setAttribute("UserId", to.getIdUsuario());
                        request.getSession().setAttribute("NivelFsx", to.getIdCategoriaUsuario());
                            if(l<=5) {
                                    request.getSession().setAttribute("Session2", request.getSession().getId()); 
                                    ArrayList list_s= new ArrayList();
                                    for (int i = l; i<=3; i++){
                                            list_s.add(""+i);
                                    }						
                                    //1 Super Administrador
                                    //2 Administrador
                                    //3 Promotor Ventas
                                    //4 Apoyo Ventas
                                    //5 Auditor						
                              request.getSession().setAttribute("ListAccesses",list_s);
                              }
                            result="5|Exito|validar/frame.html";                
                }else{
                           result="2->Usted. Esta desactivado y No es Super Administrador";
                           request.getSession().setAttribute("Session2",null);
                           throw new Exception("Alert "+request.getParameter("username")+"!, Your PIN is invalidate");                
                    }               
                }  
               }else{
               List listU= UsuarioServicio.validarSuEntrada(usuario); 
               Iterator iteratorU = listU.iterator();
                if(iteratorU.hasNext()){ result="0|Error de clave...!";}else{result="1|Personal no Registrado o no es Usuario";}               
               }        
        model.put("rsTrabajador", result);        
        return new ModelAndView("admin/validaxion",model);
        }
        
        
        
        
}*/
